/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.magicland;

import java.util.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.File;
import java.util.Map.Entry;

class Localization 
{
	private boolean Debug = true;
	
	String path;
	Hashtable<String, String> strTable;
	
	//singleton
	private static Localization instance;
        
	public static Localization getInstance()
	{
		if(instance == null)
			instance = new Localization();
		
		return instance;
	}

	private Localization( ){
                strTable = new  Hashtable<String, String>();
	}
	
	public String getText(String key){
	
		if(Config.Debug)
                     System.out.println("key"+key+" value:"+strTable.get(key));
		
                return	strTable.get(key);
	}
	
	
	public void loadResource(String file){
		try{  
			File f = new File( Config.path + file);
			FileReader fr = new FileReader(f);  
			BufferedReader br = new BufferedReader(fr);   
			String eachLine;
			String result[] = null;
			
			while( (eachLine= br.readLine())!=null){  
				
				result = eachLine.split("=");
				
				if(result[0] != null){ //key
					strTable.put(result[0],result[1]);
				}
			}   
		}catch( Exception e ){ 
				
			e.printStackTrace();	
		}	
	} 
        
        public  Hashtable<String, String> getHashTableLocalized() throws CloneNotSupportedException{
        
            return (Hashtable<String, String>)strTable.clone();
            
//          
//            Hashtable<String, String> hashtable2 = new Hashtable<String, String>();
//
//            Set<Entry<String, String>> set1 = strTable.entrySet();
//            for (Entry<String, String> e : set1)
//                hashtable2.put( e.getKey().clone(), (String)e.getValue().clone());
//            
//            return hashtable2;
        }
}